home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1862 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  46 lines

  1. Path: news.cencom.net!ns!tanp
  2. From: tanp@ns (Bill Wendling)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: What the Exon is THIS?!
  5. Date: 17 Jan 1996 05:54:29 GMT
  6. Organization: Cen-Com Internet
  7. Message-ID: <4di2ul$j77@news.cencom.net>
  8. References: <4d6rgh$rfu@abel.cc.sunysb.edu> <4dc2o1$ea8@hammy.lonestar.org>
  9. NNTP-Posting-Host: ns.cencom.net
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Gordon Burditt inexplicably wrote:
  13. } >  int (*p)[3]  is?????
  14.  
  15. } A pointer to an array of 3 integers.
  16.  
  17. } >(*p)[0] = 3; for e.g, but when I print the value using:
  18. } >
  19. } > printf("%d",(*p)[0]) I get a core dump!
  20.  
  21. } You can store into it, but when you try to access it, it core dumps?
  22. } This is rather strange.
  23.  
  24. Not really, p is only a pointer to an array of 3 integers.  No array
  25. of 3 integers has been assigned to p.  The assignment (*p)[0] = 3; seems
  26. to not have anyplace to put 3.  The correct version of this program is:
  27.  
  28. main()
  29. {
  30.     int (*p)[3];
  31.     int array[3];
  32.  
  33.     p = &array;
  34.     (*p)[0] = 3;
  35.  
  36.     print("%d\n", (*p)[0]);
  37. }
  38.  
  39. This prints out the correct value of 3.
  40.  
  41.  
  42. --
  43. Bill Wendling         | "Pinky, are you thinking what I'm thinking?"
  44. tanp@ns.cencom.net  | "I think so, Brain, but burlap chafes me so."
  45. "Boom Shanka"       | Finger me for my Geek Code...NOW!
  46.